<?php

namespace common\sources\write\loginuserpower;

use common\models\craftsman\loginuserpower;
use Yii;

class LoginUserPowerAccess implements ILoginUserPowerAccess {
	//添加制定用户权限
	public function addUserPower($data) {
		return Yii::$app->db->createCommand()->insert(loginuserpower::tableName(), [
			'userid'   => $data['login_id'],
			'powerids' => $data['powerids'],
		])->execute();
	}

	/**
	 * editUserPower 修改
	 * @param $data
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/6
	 * @return int
	 * @throws \yii\db\Exception
	 */
	public function editUserPower($data) {
		$sql = 'UPDATE ' . loginuserpower::tableName() . ' SET powerids=:powerids WHERE userid = :userid ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':powerids' => $data['powerids'],
				':userid'   => $data['login_id']
			])->execute();
	}

	public function delUserPower($data) {
		$result = loginuserpower::find()
			->where(['userid' => $data])
			->one();
		if ($result) {
			$result->delete();
		}
	}
}